package demo1;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //按奇偶排序数组 2
    public int[] sortArrayByParityII(int[] nums) {
        int n = nums.length;
        int[] ret = new int[n];
        int x = 0;
        int y = 1;
        for(int i = 0;i < n; i++){
            if(nums[i]%2==0){
                ret[x] = nums[i];
                x += 2;
            }else{
                ret[y] = nums[i];
                y += 2;
            }
        }
        return ret;
    }

    //点名
    public int takeAttendance(int[] records) {
        int n = records.length;
        if(n==1){
            return records[0]==0? 1 : 0;
        }
        int left = 0;
        int right = n-1;
        while(left<right){
            int mid = left + (right - left)/2;
            if(mid==records[mid]){
                left = mid + 1;
            }else {
                right = mid;
            }
        }
        // if(right==0 && records[0]==1){
        //     return 0;
        // }
        return left==records[n-1]?left+1:left;
    }

    //求出最多标记下标
    public int maxNumOfMarkedIndices(int[] nums) {
        int n = nums.length;
        Arrays.sort(nums);
        int count = 0;
        int key = n/2;
        int left = key-1; int right = n-1;
        while(left>=0 && right>=key){
            if(nums[left]*2 > nums[right]){
                left--;
            }else {
                left--;
                right--;
                count += 2;
            }
        }
        return count;
    }

    public static void main1(String[] args) {
        int[] nums = {34,43,23,4534,11,44};
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void main(String[] args) {
        int[] nums = {57,40,57,51,90,51,68,100,24,39,11,85,2,22,67,29,74,82,10,96,14,35,25,76,26,54,29,44,63,49,73,50,95,89,43,62,24,88,88,36,6,16,14,2,42,42,60,25,4,58,23,22,27,26,3,79,64,20,92};
        System.out.println(nums.length);
    }
}












